home *** CD-ROM | disk | FTP | other *** search
- package com.sun.xml.parser;
-
- import com.sun.xml.util.XmlChars;
- import java.io.CharConversionException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.Reader;
- import java.io.UnsupportedEncodingException;
- import java.net.URL;
- import java.util.Locale;
- import org.xml.sax.DocumentHandler;
- import org.xml.sax.ErrorHandler;
- import org.xml.sax.InputSource;
- import org.xml.sax.Locator;
- import org.xml.sax.SAXException;
- import org.xml.sax.SAXParseException;
-
- final class InputEntity implements Locator {
- private int start;
- private int finish;
- private char[] buf;
- private int lineNumber = 1;
- private boolean returnedFirstHalf = false;
- private boolean maybeInCRLF = false;
- private String name;
- private InputEntity next;
- private InputSource input;
- private Reader reader;
- private boolean isClosed;
- private ErrorHandler errHandler;
- private Locale locale;
- private StringBuffer rememberedText;
- private int startRemember;
- private boolean isPE;
- private static final int BUFSIZ = 8193;
- private static final char[] newline = new char[]{'\n'};
-
- private InputEntity() {
- }
-
- private void checkRecursion(InputEntity var1) throws SAXException {
- if (var1 != null) {
- for(InputEntity var2 = var1.next; var2 != null; var2 = var2.next) {
- if (var2.name != null && var2.name.equals(this.name)) {
- this.fatal("P-069", new Object[]{this.name});
- }
- }
-
- }
- }
-
- private boolean checkSurrogatePair(int var1) throws SAXException {
- if (var1 + 1 >= this.finish) {
- return false;
- } else {
- char var2 = this.buf[var1++];
- char var3 = this.buf[var1];
- if (var2 >= '\ud800' && var2 < '\udc00' && var3 >= '\udc00' && var3 <= '\udfff') {
- return true;
- } else {
- this.fatal("P-074", new Object[]{Integer.toHexString(var2 & '\uffff'), Integer.toHexString(var3 & '\uffff')});
- return false;
- }
- }
- }
-
- public void close() {
- try {
- if (this.reader != null && !this.isClosed) {
- this.reader.close();
- }
-
- this.isClosed = true;
- } catch (IOException var1) {
- }
-
- }
-
- private void fatal(String var1, Object[] var2) throws SAXException {
- SAXParseException var3 = new SAXParseException(Parser.messages.getMessage(this.locale, var1, var2), this);
- this.close();
- this.errHandler.fatalError(var3);
- throw var3;
- }
-
- private void fillbuf() throws IOException, SAXException {
- if (this.reader != null && !this.isClosed) {
- if (this.startRemember != 0) {
- if (this.rememberedText == null) {
- this.rememberedText = new StringBuffer(this.buf.length);
- }
-
- this.rememberedText.append(this.buf, this.startRemember, this.start - this.startRemember);
- }
-
- boolean var1 = this.finish > 0 && this.start > 0;
- if (var1) {
- --this.start;
- }
-
- int var2 = this.finish - this.start;
- System.arraycopy(this.buf, this.start, this.buf, 0, var2);
- this.start = 0;
- this.finish = var2;
-
- try {
- var2 = this.buf.length - var2;
- var2 = this.reader.read(this.buf, this.finish, var2);
- } catch (UnsupportedEncodingException var4) {
- this.fatal("P-075", new Object[]{((Throwable)var4).getMessage()});
- } catch (CharConversionException var5) {
- this.fatal("P-076", new Object[]{((Throwable)var5).getMessage()});
- }
-
- if (var2 >= 0) {
- this.finish += var2;
- } else {
- this.close();
- }
-
- if (var1) {
- ++this.start;
- }
-
- if (this.startRemember != 0) {
- this.startRemember = 1;
- }
-
- }
- }
-
- public int getColumnNumber() {
- return -1;
- }
-
- public String getEncoding() {
- if (this.reader == null) {
- return null;
- } else if (this.reader instanceof XmlReader) {
- return ((XmlReader)this.reader).getEncoding();
- } else {
- return this.reader instanceof InputStreamReader ? ((InputStreamReader)this.reader).getEncoding() : null;
- }
- }
-
- public static InputEntity getInputEntity(ErrorHandler var0, Locale var1) {
- InputEntity var2 = new InputEntity();
- var2.errHandler = var0;
- var2.locale = var1;
- return var2;
- }
-
- public int getLineNumber() {
- Locator var1 = this.getLocator();
- return var1 == this ? this.lineNumber : var1.getLineNumber();
- }
-
- private Locator getLocator() {
- InputEntity var1;
- for(var1 = this; var1 != null && var1.input == null; var1 = var1.next) {
- }
-
- return var1 == null ? this : var1;
- }
-
- public String getName() {
- return this.name;
- }
-
- public char getNameChar() throws IOException, SAXException {
- if (this.finish <= this.start) {
- this.fillbuf();
- }
-
- if (this.finish > this.start) {
- char var1 = this.buf[this.start++];
- if (XmlChars.isNameChar(var1)) {
- return var1;
- }
-
- --this.start;
- }
-
- return '\u0000';
- }
-
- public String getPublicId() {
- Locator var1 = this.getLocator();
- return var1 == this ? this.input.getPublicId() : var1.getPublicId();
- }
-
- public String getSystemId() {
- Locator var1 = this.getLocator();
- return var1 == this ? this.input.getSystemId() : var1.getSystemId();
- }
-
- public char getc() throws IOException, SAXException {
- if (this.finish <= this.start) {
- this.fillbuf();
- }
-
- if (this.finish > this.start) {
- char var1 = this.buf[this.start++];
- if (this.returnedFirstHalf) {
- if (var1 >= '\udc00' && var1 <= '\udfff') {
- this.returnedFirstHalf = false;
- return var1;
- }
-
- this.fatal("P-070", new Object[]{Integer.toHexString(var1)});
- }
-
- if (var1 >= ' ' && var1 <= '\ud7ff' || var1 == '\t' || var1 >= '\ue000' && var1 <= 'ÔøΩ') {
- return var1;
- }
-
- if (var1 == '\r' && !this.isInternal()) {
- this.maybeInCRLF = true;
- var1 = this.getc();
- if (var1 != '\n') {
- this.ungetc();
- }
-
- this.maybeInCRLF = false;
- ++this.lineNumber;
- return '\n';
- }
-
- if (var1 == '\n' || var1 == '\r') {
- if (!this.isInternal() && !this.maybeInCRLF) {
- ++this.lineNumber;
- }
-
- return var1;
- }
-
- if (var1 >= '\ud800' && var1 < '\udc00') {
- this.returnedFirstHalf = true;
- return var1;
- }
-
- this.fatal("P-071", new Object[]{Integer.toHexString(var1)});
- }
-
- throw new EndOfInputException();
- }
-
- public boolean ignorableWhitespace(DocumentHandler var1) throws IOException, SAXException {
- boolean var3 = false;
- int var4 = this.start;
-
- while(true) {
- if (this.finish <= this.start) {
- if (var3) {
- var1.ignorableWhitespace(this.buf, var4, this.start - var4);
- }
-
- this.fillbuf();
- var4 = this.start;
- }
-
- if (this.finish <= this.start) {
- return var3;
- }
-
- char var2 = this.buf[this.start++];
- switch (var2) {
- case '\n':
- if (!this.isInternal()) {
- ++this.lineNumber;
- }
- case '\t':
- case ' ':
- var3 = true;
- break;
- case '\r':
- var3 = true;
- if (!this.isInternal()) {
- ++this.lineNumber;
- }
-
- var1.ignorableWhitespace(this.buf, var4, this.start - 1 - var4);
- var1.ignorableWhitespace(newline, 0, 1);
- if (this.start < this.finish && this.buf[this.start] == '\n') {
- ++this.start;
- }
-
- var4 = this.start;
- break;
- default:
- this.ungetc();
- if (var3) {
- var1.ignorableWhitespace(this.buf, var4, this.start - var4);
- }
-
- return var3;
- }
- }
- }
-
- public void init(InputSource var1, String var2, InputEntity var3, boolean var4) throws IOException, SAXException {
- this.input = var1;
- this.isPE = var4;
- this.reader = var1.getCharacterStream();
- if (this.reader == null) {
- InputStream var5 = var1.getByteStream();
- if (var5 == null) {
- this.reader = XmlReader.createReader((new URL(var1.getSystemId())).openStream());
- } else if (var1.getEncoding() != null) {
- this.reader = XmlReader.createReader(var1.getByteStream(), var1.getEncoding());
- } else {
- this.reader = XmlReader.createReader(var1.getByteStream());
- }
- }
-
- this.next = var3;
- this.buf = new char[8193];
- this.name = var2;
- this.checkRecursion(var3);
- }
-
- public void init(char[] var1, String var2, InputEntity var3, boolean var4) throws SAXException {
- this.next = var3;
- this.buf = var1;
- this.finish = var1.length;
- this.name = var2;
- this.isPE = var4;
- this.checkRecursion(var3);
- }
-
- public boolean isDocument() {
- return this.next == null;
- }
-
- public boolean isEOF() throws IOException, SAXException {
- if (this.start >= this.finish) {
- this.fillbuf();
- return this.start >= this.finish;
- } else {
- return false;
- }
- }
-
- public boolean isInternal() {
- return this.reader == null;
- }
-
- public boolean isParameterEntity() {
- return this.isPE;
- }
-
- public boolean maybeWhitespace() throws IOException, SAXException {
- boolean var2 = false;
- boolean var3 = false;
-
- while(true) {
- if (this.finish <= this.start) {
- this.fillbuf();
- }
-
- if (this.finish <= this.start) {
- return var2;
- }
-
- char var1 = this.buf[this.start++];
- if (var1 != ' ' && var1 != '\t' && var1 != '\n' && var1 != '\r') {
- --this.start;
- return var2;
- }
-
- var2 = true;
- if ((var1 == '\n' || var1 == '\r') && !this.isInternal()) {
- if (var1 != '\n' || !var3) {
- ++this.lineNumber;
- var3 = false;
- }
-
- if (var1 == '\r') {
- var3 = true;
- }
- }
- }
- }
-
- public boolean parsedContent(DocumentHandler var1, ElementValidator var2) throws IOException, SAXException {
- int var4;
- int var3 = var4 = this.start;
- boolean var5 = false;
-
- while(true) {
- if (var4 >= this.finish) {
- if (var4 > var3) {
- var2.text();
- var1.characters(this.buf, var3, var4 - var3);
- var5 = true;
- this.start = var4;
- }
-
- if (this.isEOF()) {
- return var5;
- }
-
- var3 = this.start;
- var4 = var3 - 1;
- } else {
- char var6 = this.buf[var4];
- if ((var6 <= ']' || var6 > '\ud7ff') && (var6 >= '&' || var6 < ' ') && (var6 <= '<' || var6 >= ']') && (var6 <= '&' || var6 >= '<') && var6 != '\t' && (var6 < '\ue000' || var6 > 'ÔøΩ')) {
- if (var6 == '<' || var6 == '&') {
- break;
- }
-
- if (var6 == '\n') {
- if (!this.isInternal()) {
- ++this.lineNumber;
- }
- } else if (var6 == '\r') {
- if (!this.isInternal()) {
- var1.characters(this.buf, var3, var4 - var3);
- var1.characters(newline, 0, 1);
- var5 = true;
- ++this.lineNumber;
- if (this.finish > var4 + 1 && this.buf[var4 + 1] == '\n') {
- ++var4;
- }
-
- var3 = this.start = var4 + 1;
- }
- } else if (var6 == ']') {
- switch (this.finish - var4) {
- case 2:
- if (this.buf[var4 + 1] != ']') {
- break;
- }
- case 1:
- if (this.reader != null && !this.isClosed) {
- if (var4 == var3) {
- throw new InternalError("fillbuf");
- }
-
- --var4;
- if (var4 > var3) {
- var2.text();
- var1.characters(this.buf, var3, var4 - var3);
- var5 = true;
- this.start = var4;
- }
-
- this.fillbuf();
- var3 = var4 = this.start;
- }
- break;
- default:
- if (this.buf[var4 + 1] == ']' && this.buf[var4 + 2] == '>') {
- this.fatal("P-072", (Object[])null);
- }
- }
- } else if (var6 >= '\ud800' && var6 <= '\udfff') {
- if (var4 + 1 >= this.finish) {
- if (var4 > var3) {
- var2.text();
- var1.characters(this.buf, var3, var4 - var3);
- var5 = true;
- this.start = var4 + 1;
- }
-
- if (this.isEOF()) {
- this.fatal("P-081", new Object[]{Integer.toHexString(var6)});
- }
-
- var3 = this.start;
- var4 = var3;
- } else {
- if (!this.checkSurrogatePair(var4)) {
- --var4;
- break;
- }
-
- ++var4;
- }
- } else {
- this.fatal("P-071", new Object[]{Integer.toHexString(var6)});
- }
- }
- }
-
- ++var4;
- }
-
- if (var4 == var3) {
- return var5;
- } else {
- var2.text();
- var1.characters(this.buf, var3, var4 - var3);
- this.start = var4;
- return true;
- }
- }
-
- public boolean peek(String var1, char[] var2) throws IOException, SAXException {
- int var3;
- if (var2 != null) {
- var3 = var2.length;
- } else {
- var3 = var1.length();
- }
-
- if (this.finish <= this.start || this.finish - this.start < var3) {
- this.fillbuf();
- }
-
- if (this.finish <= this.start) {
- return false;
- } else {
- int var4;
- if (var2 != null) {
- for(var4 = 0; var4 < var3 && this.start + var4 < this.finish; ++var4) {
- if (this.buf[this.start + var4] != var2[var4]) {
- return false;
- }
- }
- } else {
- for(var4 = 0; var4 < var3 && this.start + var4 < this.finish; ++var4) {
- if (this.buf[this.start + var4] != var1.charAt(var4)) {
- return false;
- }
- }
- }
-
- if (var4 < var3) {
- if (this.reader != null && !this.isClosed) {
- if (var3 > this.buf.length) {
- this.fatal("P-077", new Object[]{new Integer(this.buf.length)});
- }
-
- this.fillbuf();
- return this.peek(var1, var2);
- } else {
- return false;
- }
- } else {
- this.start += var3;
- return true;
- }
- }
- }
-
- public boolean peekc(char var1) throws IOException, SAXException {
- if (this.finish <= this.start) {
- this.fillbuf();
- }
-
- if (this.finish > this.start) {
- if (this.buf[this.start] == var1) {
- ++this.start;
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
-
- public InputEntity pop() throws IOException {
- this.close();
- return this.next;
- }
-
- public String rememberText() {
- String var1;
- if (this.rememberedText != null) {
- this.rememberedText.append(this.buf, this.startRemember, this.start - this.startRemember);
- var1 = this.rememberedText.toString();
- } else {
- var1 = new String(this.buf, this.startRemember, this.start - this.startRemember);
- }
-
- this.startRemember = 0;
- this.rememberedText = null;
- return var1;
- }
-
- public void startRemembering() {
- if (this.startRemember != 0) {
- throw new InternalError();
- } else {
- this.startRemember = this.start;
- }
- }
-
- public void ungetc() {
- if (this.start == 0) {
- throw new InternalError("ungetc");
- } else {
- --this.start;
- if (this.buf[this.start] != '\n' && this.buf[this.start] != '\r') {
- if (this.returnedFirstHalf) {
- this.returnedFirstHalf = false;
- }
- } else if (!this.isInternal()) {
- --this.lineNumber;
- }
-
- }
- }
-
- public boolean unparsedContent(DocumentHandler var1, ElementValidator var2, boolean var3, String var4) throws IOException, SAXException {
- if (!this.peek("![CDATA[", (char[])null)) {
- return false;
- } else {
- if (var1 instanceof LexicalEventListener) {
- ((LexicalEventListener)var1).startCDATA();
- }
-
- while(true) {
- boolean var6 = false;
- boolean var8 = var3;
-
- int var5;
- for(var5 = this.start; var5 < this.finish; ++var5) {
- char var7 = this.buf[var5];
- if (!XmlChars.isChar(var7)) {
- var8 = false;
- if (var7 >= '\ud800' && var7 <= '\udfff') {
- if (!this.checkSurrogatePair(var5)) {
- --var5;
- break;
- }
-
- ++var5;
- continue;
- }
-
- this.fatal("P-071", new Object[]{Integer.toHexString(this.buf[var5])});
- }
-
- if (var7 == '\n') {
- if (!this.isInternal()) {
- ++this.lineNumber;
- }
- } else if (var7 == '\r') {
- if (!this.isInternal()) {
- if (var8) {
- if (var4 != null) {
- this.errHandler.error(new SAXParseException(Parser.messages.getMessage(this.locale, var4), this));
- }
-
- var1.ignorableWhitespace(this.buf, this.start, var5 - this.start);
- var1.ignorableWhitespace(newline, 0, 1);
- } else {
- var2.text();
- var1.characters(this.buf, this.start, var5 - this.start);
- var1.characters(newline, 0, 1);
- }
-
- ++this.lineNumber;
- if (this.finish > var5 + 1 && this.buf[var5 + 1] == '\n') {
- ++var5;
- }
-
- this.start = var5 + 1;
- }
- } else if (var7 != ']') {
- if (var7 != ' ' && var7 != '\t') {
- var8 = false;
- }
- } else if (var5 + 2 < this.finish) {
- if (this.buf[var5 + 1] == ']' && this.buf[var5 + 2] == '>') {
- var6 = true;
- break;
- }
-
- var8 = false;
- } else {
- --var5;
- this.fillbuf();
- var5 = this.start - 1;
- }
- }
-
- if (var8) {
- if (var4 != null) {
- this.errHandler.error(new SAXParseException(Parser.messages.getMessage(this.locale, var4), this));
- }
-
- var1.ignorableWhitespace(this.buf, this.start, var5 - this.start);
- } else {
- var2.text();
- var1.characters(this.buf, this.start, var5 - this.start);
- }
-
- if (var6) {
- this.start = var5 + 3;
- if (var1 instanceof LexicalEventListener) {
- ((LexicalEventListener)var1).endCDATA();
- }
-
- return true;
- }
-
- this.start = var5;
- if (this.isEOF()) {
- this.fatal("P-073", (Object[])null);
- }
- }
- }
- }
- }
-